#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_SUBST([YSE_VERSION], [0.7])
AC_PREREQ([2.69])
AC_INIT([libYSE], [0.7], [yvan@attr-x.net],[libYSE],[http://attr-x.net/yse/])

AC_CONFIG_AUX_DIR(cfg)
AC_CONFIG_SRCDIR([src/playlist.cpp])
AC_CANONICAL_TARGET([])
AC_CONFIG_MACRO_DIR([M4])
AC_CONFIG_HEADERS([src/config.h])

AM_INIT_AUTOMAKE
AM_SILENT_RULES([yes])

# dnl Add parameters for aclocal
AC_SUBST(ACLOCAL_AMFLAGS, "-I M4 -I cfg")

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC

# check for android
AC_CANONICAL_HOST

# Do not check for F77.
define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl

AC_PROG_LIBTOOL
LT_PROG_RC

# Checks for libraries.
LT_INIT([disable-static])



AC_PROG_INSTALL
AC_PROG_LN_S

#------------------------------------------------------------------------------------
# Rules for library version information:
#
#  1. Start with version information of `0:0:0' for each libtool library.
#  2. Update the version information only immediately before a public release of
#     your software. More frequent updates are unnecessary, and only guarantee
#     that the current interface number gets larger faster.
#  3. If the library source code has changed at all since the last update, then
#     increment revision (`c:r:a' becomes `c:r+1:a').
#  4. If any interfaces have been added, removed, or changed since the last update,
#     increment current, and set revision to 0.
#  5. If any interfaces have been added since the last public release, then increment
#     age.
#  6. If any interfaces have been removed since the last public release, then set age
#     to 0.

CLEAN_VERSION=`echo $PACKAGE_VERSION | $SED "s/p.*//"`
VERSION_MINOR=`echo $CLEAN_VERSION | $SED "s/.*\.//"`

SHARED_VERSION_INFO="1:$VERSION_MINOR:0"


#------------------------------------------------------------------------------------

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([stdlib.h string.h sys/time.h termios.h unistd.h])
AC_HEADER_SYS_WAIT

# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_INT8_T
AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T

# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([atexit memset pow select sqrt strchr])

PKG_CHECK_MODULES([SNDFILE], [sndfile >= 1.0.25])


case $host in
  arm*)
    echo "No PortAudio needed for Android"
    BOOST_REQUIRE([1.53])
    # the boost checks do not seem to work. Why is this?

    ;;
  *) 
    PKG_CHECK_MODULES([PORTAUDIO], [portaudio-2.0 >= 19])
    BOOST_REQUIRE([1.53])
    BOOST_THREADS
    BOOST_ATOMIC
    ;;
esac


AC_SUBST(SHARED_VERSION_INFO)
GLOBAL_INCLUDE=${includedir}
AC_SUBST(GLOBAL_INCLUDE)
includedir=${includedir}/YSE

CFLAGS="$CFLAGS $SNDFILE_CFLAGS $PORTAUDIO_CFLAGS"
LIBS="$LIBS $SNDFILE_LIBS $PORTAUDIO_LIBS"
CXXFLAGS=${CFLAGS}


AC_CONFIG_FILES([Makefile src/Makefile YSE.pc])
AC_OUTPUT

#====================================================================================

AC_MSG_RESULT([
-=-=-=-=-=-=-=-=-=-= Configuration Complete =-=-=-=-=-=-=-=-=-=-

  Configuration summary :

    libYSE version : ...................... ${VERSION}

    Host CPU : ............................ ${host_cpu}
    Host Vendor : ......................... ${host_vendor}
    Host OS : ............................. ${host_os}

])

AC_MSG_RESULT([[
  Installation directories :

    Library directory : ................... $libdir
    Include directory : ................... $includedir
    Program directory : ................... $bindir
    Pkgconfig directory : ................. $libdir/pkgconfig
    HTML docs directory : ................. $htmldocdir
    
  Compiler options :
    CFlags : ${CFLAGS}
    Libs   : ${LIBS}
]])
